<template>
  <div class="container">
    <div class="title">虚拟仿真实训管理系统</div>
    <div class="header">
      <h1>欢迎您：{{ name }}</h1>
      <h1>{{ bjTime }}</h1>
    </div>
    <section class="hero-section">
      <div class="card-grid">
        <a class="card" href="http://jwzx.cqupt.edu.cn/">
          <div class="card__background" :style="backgroundStyle1" />
          <div class="card__content">
            <p class="card__category">教务在线</p>
            <h3 class="card__heading">教务在线</h3>
          </div>
        </a>
        <a class="card" href="https://gis.cqupt.edu.cn/">
          <div class="card__background" :style="backgroundStyle2" />
          <div class="card__content">
            <p class="card__category">可视化校园</p>
            <h3 class="card__heading">可视化校园</h3>
          </div>
        </a>
        <a class="card" href="http://ehall.cqupt.edu.cn/new/index.html">
          <div class="card__background" :style="backgroundStyle3" />
          <div class="card__content">
            <p class="card__category">服务大厅</p>
            <h3 class="card__heading">服务大厅</h3>
          </div>
        </a>
        <a class="card" href="http://www.cqupt.edu.cn/">
          <div class="card__background" :style="backgroundStyle4" />
          <div class="card__content">
            <p class="card__category">学校官网</p>
            <h3 class="card__heading">学校官网</h3>
          </div>
        </a>
      </div>
    </section>
  </div>

</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  data() {
    return {
      bjTime: this.getCurrentBjTime() // 初始化北京时间
    }
  },
  computed: {
    backgroundStyle1() {
      return {
        backgroundImage: "url('https://files.catbox.moe/p32qye.jpg')"
      }
    },
    backgroundStyle2() {
      return {
        backgroundImage: "url('https://files.catbox.moe/11n1ak.jpg')"
      }
    },
    backgroundStyle3() {
      return {
        backgroundImage: "url('https://files.catbox.moe/0ntnb1.jpg')"
      }
    },
    backgroundStyle4() {
      return {
        backgroundImage: "url('https://files.catbox.moe/ggq6tf.png')"
      }
    },
    ...mapGetters([
      'name'
    ]),
    lunarDate() {
      // 通过合适的方式获取农历日期
      return '农历日期'
    },
    solarDate() {
      // 通过合适的方式获取阳历日期
      return '阳历日期'
    }
  },
  mounted() {
    // 每隔一秒更新一次北京时间
    this.timer = setInterval(this.updateBjTime, 1000)
  },
  beforeDestroy() {
    // 在组件销毁前清除定时器
    clearInterval(this.timer)
  },
  methods: {
    getCurrentBjTime() {
      return new Date(+new Date() + 8 * 3600 * 1000)
        .toISOString()
        .replace(/-/, '年')
        .replace(/-/g, '月')
        .replace(/T/g, '日 ')
        .replace(/\.[\d]{3}Z/, '')
    },
    updateBjTime() {
      this.bjTime = this.getCurrentBjTime() // 更新北京时间
    }
  }
}
</script>

<style>
:root{
  --background-dark: #2d3548;
  --text-light: rgba(255,255,255,0.6);
  --text-lighter: rgba(255,255,255,0.9);
  --spacing-s: 8px;
  --spacing-m: 16px;
  --spacing-l: 24px;
  --spacing-xl: 32px;
  --spacing-xxl: 64px;
  --width-container: 1200px;
}

*{
  border: 0;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html{
  height: 100%;
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
}

body{
  height: 100%;
}

.hero-section{
  align-items: flex-start;
  display: flex;
  min-height: 100%;
  justify-content: center;
  padding: var(--spacing-xxl) var(--spacing-l);
}

.card-grid{
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  grid-column-gap: var(--spacing-l);
  grid-row-gap: var(--spacing-l);
  max-width: var(--width-container);
  width: 100%;
}

@media(min-width: 540px){
  .card-grid{
    grid-template-columns: repeat(2, 1fr);
  }
}

@media(min-width: 960px){
  .card-grid{
    grid-template-columns: repeat(4, 1fr);
  }
}

.card{
  list-style: none;
  position: relative;
}

.card:before{
  content: '';
  display: block;
  padding-bottom: 150%;
  width: 100%;
}

.card__background{
  background-size: cover;
  background-position: center;
  border-radius: var(--spacing-l);
  bottom: 0;
  filter: brightness(0.75) saturate(1.2) contrast(0.85);
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transform-origin: center;
  trsnsform: scale(1) translateZ(0);
  transition:
    filter 200ms linear,
    transform 200ms linear;
}

.card:hover .card__background{
  transform: scale(1.05) translateZ(0);
}

.card-grid:hover > .card:not(:hover) .card__background{
  filter: brightness(0.5) saturate(0) contrast(1.2) blur(20px);
}

.card__content{
  left: 0;
  padding: var(--spacing-l);
  position: absolute;
  top: 0;
}

.card__category{
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: var(--spacing-s);
  text-transform: uppercase;
}

.card__heading{
  color: var(--text-lighter);
  font-size: 1.9rem;
  text-shadow: 2px 2px 20px rgba(0,0,0,0.2);
  line-height: 1.4;
  word-spacing: 100vw;
}
</style>

<style lang="scss" scoped>
  .container{
    .title{
      text-align: center;
      font-size: 80px;
      font-weight: bold;
      color: #009ba0;
    }
    .header{
      margin-top: 50px;
      text-align: center;
    }

    .hero-section{
      margin-top:60px;
      border-radius: 10px;
    }
  }
</style>
